<?php

/*
 *  禁止显示debug信息
 */

function no_debug() {
	C('SHOW_RUN_TIME', false); // 运行时间显示
	C('SHOW_ADV_TIME', false); // 显示详细的运行时间
	C('SHOW_DB_TIMES', false); // 显示数据库查询和写入次数
	C('SHOW_CACHE_TIMES', false); // 显示缓存操作次数
	C('SHOW_USE_MEM', false); // 显示内存开销
	C('SHOW_PAGE_TRACE', false); // 显示页面Trace信息 由Trace文件定义和Action操作赋值
}

/*
 *  随机获取昵称
 */

function get_rand_name($except) {
	if (is_string($except)) {
		$except = explode(",", $except);
	}
	$nickname = D("Nickname");
	$result = $nickname->field("nickname")->order("RAND()");
	if (isset($except) && is_array($except)) {
		$result->where(array("nickname" => array("not in", implode(",", $except))));
	}
	return $result->getField("nickname");
}

/*
 *  随机获取昵称
 */

function get_rand_name_by_tweetsId($tid) {
	$except = D("Comment")->where("tweets_id = '$tid' ")->field("nickname")->group("nickname")->select();
	if (is_array($except)) {
		foreach ($except as $key => $value) {
			$except[$key] = $value['nickname'];
		}
	}
	$nickname = D("Nickname");
	$result = $nickname->field("nickname")->order("RAND()");
	if (isset($except) && is_array($except)) {
		$result->where(array("nickname" => array("not in", implode(",", $except))));
	}
	return $result->getField("nickname");
}

//添加Notice
function notice_log($uid=0, $type_id=0, $school_id=0, $tweets_id=0, $content='') {
	if (is_object($content) || is_array($content)) {
		$content = json_encode($content);
	}
	if (!($uid && $type_id && $tweets_id))
		return FALSE;
	$notice = D("Notice")->where("type_id=" . $type_id . " and user_id=" . $uid . " and tweets_id=" . $tweets_id)->find();
	if ($notice) {
		$data["notice_id"] = $notice['notice_id'];
		$data["content"] = $content;
		$data["school_id"] = $school_id;
		$data["update_time"] = time();
		if ($notice['status'] == 1) {
			$data["count"] = 1;
			$data["status"] = 1;
		} else {
			$data["count"] = $notice["count"] + 1;
		}
		D("Notice")->save($data);
	} else {
		$data["user_id"] = $uid;
		$data["type_id"] = $type_id;
		$data["school_id"] = $school_id;
		$data["tweets_id"] = $tweets_id;
		$data["content"] = $content;
		$data["count"] = 1;
		$data["update_time"] = time();
		$data["create_time"] = time();
		D("Notice")->add($data);
	}
	S("notice_new_" . $uid, null);
}

//获取学校信息
function get_shcool_info($where) {
	if (!$where)
		return false;
	$schools = D("School")->cache("school")->where("status=1")->select();
	if (is_array($where)) {
		$school = list_search($schools, $where);
	} else {
		$school = list_search($schools, array('school_id' => $where));
	}
	if ($school) {
		return $school[0];
	} else {
		return null;
	}
}

?>
